package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TlGoods;
import com.qf.mapper.AdminGoodsMapper;
import com.qf.service.AdminGoodsService;
import com.qf.utils.Mycode;
import com.qf.utils.ResultMsg;
import org.springframework.stereotype.Service;

@Service
public class AdminGoodsServiceImpl extends ServiceImpl<AdminGoodsMapper, TlGoods> implements AdminGoodsService {
    @Override
    public ResultMsg findgoods(int page, int limit) {
        Page<TlGoods> shopgoods = new Page<>(page, limit);
        Page<TlGoods> page1 = super.page(shopgoods);
        return ResultMsg.SUCCESS(page1);


    }

    @Override
    public ResultMsg findOneById(Integer gid) {
        TlGoods byId = super.getById(gid);
        return ResultMsg.SUCCESS(byId);
    }

    @Override
    public ResultMsg modify(TlGoods goods) {
        goods.setGoodsStock(18);
        boolean b = super.saveOrUpdate(goods);
        if (b)
            return ResultMsg.SUCCESS();
        return ResultMsg.ERROR(Mycode.GOODSFIND_ERRO);

    }

    @Override
    public ResultMsg delete(int goodsId) {
        boolean b = super.removeById(goodsId);
        if (b)
            return ResultMsg.SUCCESS();
        return ResultMsg.ERROR(Mycode.DELETEGOODS_ERRO,"删除商品失败");
    }
}
